package day16.homework13;

// 父类 Ball
class Ball {
    public void play() {
        System.out.println("Playing with a generic ball.");
    }
}

// 子类 Basketball
class Basketball extends Ball {
    @Override
    public void play() {
        System.out.println("Dribbling and shooting the basketball!");
    }
}

// 子类 Football
class Football extends Ball {
    @Override
    public void play() {
        System.out.println("Kicking the football on the field!");
    }
}

// 测试类
public class Test1_ball {
    public static void playBall(Ball ball) {
        ball.play(); // 多态体现：调用的是实际对象的 play() 方法
    }

    public static void main(String[] args) {
        Ball b = new Ball();           // 父类对象
        Ball b2 = new Basketball();    // 父类引用指向子类对象
        Ball b3 = new Football();      // 父类引用指向子类对象

        Test1_ball.playBall(b);   // 输出：Playing with a generic ball.
        Test1_ball.playBall(b2);  // 输出：Dribbling and shooting the basketball!
        Test1_ball.playBall(b3);  // 输出：Kicking the football on the field!
    }
}
